/*
* Copyright 2015 2dfire.com All right reserved. This software is the
* confidential and proprietary information of 2dfire.com ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with 2dfire.com.
*/
package com.dfire.mtm.executor;

import com.dfire.mtm.taskNode.TaskData;
import com.dfire.mtm.taskNode.TaskNode;

/**
 * @author guipi
 * @description
 * @date 2018/10/23
 * ----------重大变更记录------------
 */
public abstract class AbstractMtmRunnable implements MtmRunnable {

    protected TaskNode taskNode;

    /**
     * 是否准备就绪
     */
    protected boolean ready = true;

    @Override
    public TaskNode getTaskNode() {
        return taskNode;
    }

    @Override
    public void setTaskNode(TaskNode taskNode) {
        this.taskNode = taskNode;
    }

    @Override
    public <T> TaskData<T> getData() {
        checkNode();
        return taskNode.nextData();
    }

    @Override
    public <T> T getData(String task) {
        checkNode();
        return taskNode.getData(task);
    }

    @Override
    public <T> boolean pushData(String task, T data) {
        checkNode();
        return taskNode.pushData(task, data);
    }

    @Override
    public <T> boolean pushData(String task, String nodeName, T data) {
        checkNode();
        return taskNode.pushData(task, nodeName, data);
    }

    @Override
    public boolean isReady() {
        return ready;
    }

    @Override
    public void setReady(boolean ready) {
        this.ready = ready;
    }

    private void checkNode() {
        if (taskNode == null) {
            throw new NullPointerException("taskNode 为空");
        }
    }
}
